package gae.testjig.client.eventbus;

import gae.testjig.client.ClientChannelId;

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.event.shared.HandlerRegistration;


public class EchoEvent extends GwtEvent<EchoEvent.Handler> {

	public interface Handler extends EventHandler {
		public void onEcho(EchoEvent event);
	}
	
	static private Type<Handler> TYPE = new Type<Handler>();
	static public HandlerRegistration registerToSource(EventBus bus, ClientChannelId source, Handler handler) {
		return bus.addHandlerToSource(TYPE, source, handler);
	}
	
	private String message;
	
	public EchoEvent(String message) {
		this.message = message;
	}

	@Override
	protected void dispatch(Handler handler) {
		handler.onEcho(this);
	}

	@Override
	public Type<Handler> getAssociatedType() {
		return TYPE;
	}

	public String getMessage() {
		return message;
	}

}
